package array;

import cn.hutool.core.util.RandomUtil;
import org.junit.jupiter.api.Test;
import java.util.Arrays;

public class TestArray {

    /**
     * 数组复制：System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
     *   src：源
     *   dest：目标
     *   pos：起始位置
     *   length：长度
     */
    @Test
    public void test01() {
        int[] arr = new int[5];
        int[] copy = new int[10];
        for (int i = 0; i < 5; i++) {
            arr[i] = RandomUtil.randomInt(-100, 100);
        }
        System.arraycopy(arr, 0, copy, 0, arr.length);
        System.out.println(Arrays.toString(arr));  // [-79, -4, -71, 5, -24]
        System.out.println(Arrays.toString(copy));  // [-79, -4, -71, 5, -24, 0, 0, 0, 0, 0]
    }

}
